package peng.yang.express.Adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.io.File;
import java.util.List;

import peng.yang.express.Bean.PhoneMembers;
import peng.yang.express.Bean.PhoneRequest;
import peng.yang.express.R;

/**
 * Created by Administrator on 2016/7/2.
 */
public class LeftListViewAdapter extends BaseAdapter {
    private List<PhoneMembers> list;
    private Context context;
    private LayoutInflater inflater;

    public LeftListViewAdapter (Context context, List<PhoneMembers> list) {
        this.list = list;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHandler handler = new ViewHandler();
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.left_listview_item, null);
            handler.expImage = (ImageView) convertView.findViewById(R.id.iv_expImage);
            handler.expName= (TextView) convertView.findViewById(R.id.tv_expName);
            convertView.setTag(handler);
        } else {
            handler = (ViewHandler) convertView.getTag();
        }

        String path= list.get(position).getFileImagePath().toString();
        String expName = list.get(position).getExpName().toString();

//                FileInputStream is = new FileInputStream(path);
//               Bitmap bitmap1= BitmapFactory.decodeStream(is);
        File file = new File(context.getFilesDir(),path);
        Bitmap bitmap1 = BitmapFactory.decodeFile(file.getAbsolutePath());
        handler.expImage.setImageBitmap(bitmap1);
        handler.expName.setText(expName);

        return convertView;
    }
    static class ViewHandler {
        private ImageView expImage;
        private TextView expName;

    }
}
